package com.example.springaop2;

import com.example.springaop2.proxy.CGLibInterceptor;
import com.example.springaop2.proxy.JDKInvocationHandler;
import com.example.springaop2.realSubject.RealHouseSubject;
import com.example.springaop2.subject.HouseSubject;
import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.Enhancer;

import java.lang.reflect.Proxy;

public class Main {
    public static void main1(String[] args) {
        HouseSubject target = new RealHouseSubject();
        //创建⼀个代理类：通过被代理类、被代理实现的接⼝、⽅法调⽤处理器来创建
        HouseSubject proxy = (HouseSubject) Proxy.newProxyInstance(
                target.getClass().getClassLoader(),
                new Class[]{HouseSubject.class},
                new JDKInvocationHandler(target)
        );
        proxy.saleHouse();
    }

    public static void main(String[] args) {
        HouseSubject target = new RealHouseSubject();
        HouseSubject proxy = (HouseSubject) Enhancer.create(target.getClass(),new CGLibInterceptor(target));
        proxy.saleHouse();
    }
}
